<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()

// 统计数据
const statistics = ref({
  userCount: 2458,
  orderCount: 1256,
  attractionCount: 86,
  activityCount: 42,
  totalRevenue: 1256800,
  todayRevenue: 25680
})

// 快速入口
const quickEntries = [
  { title: '用户管理', icon: 'user', path: '/users', color: '#1890ff' },
  { title: '订单管理', icon: 'shop', path: '/orders', color: '#52c41a' },
  { title: '景点管理', icon: 'location', path: '/attractions', color: '#722ed1' },
  { title: '活动管理', icon: 'calendar', path: '/activities', color: '#faad14' },
  { title: '统计报表', icon: 'chart', path: '/statistics', color: '#eb2f96' },
  { title: '系统设置', icon: 'setting', path: '/settings', color: '#13c2c2' }
]

// 待办事项
const todoList = ref([
  { title: '审核新用户注册', status: 'pending', time: '2025-01-15' },
  { title: '处理退款申请', status: 'urgent', time: '2025-01-15' },
  { title: '更新景点信息', status: 'normal', time: '2025-01-16' },
  { title: '发布新活动', status: 'normal', time: '2025-01-17' }
])

// 系统公告
const notices = ref([
  { title: '系统升级通知', content: '系统将于2025年1月20日凌晨2点进行升级维护，预计耗时2小时。', date: '2025-01-15' },
  { title: '新功能发布', content: '订单管理模块新增批量导出功能，欢迎体验使用。', date: '2025-01-14' },
  { title: '操作指南更新', content: '用户管理模块操作指南已更新，请查看最新文档。', date: '2025-01-13' }
])

// 格式化金额
const formatCurrency = (value) => {
  return new Intl.NumberFormat('zh-CN', {
    style: 'currency',
    currency: 'CNY',
    minimumFractionDigits: 2
  }).format(value)
}

onMounted(() => {
  // 获取用户信息
  userStore.getUserInfo()
})
</script>

<template>
  <div class="home-container">
    <t-row :gutter="[24, 24]">
      <!-- 欢迎信息 -->
      <t-col :span="24">
        <div class="welcome-banner">
          <div class="welcome-content">
            <div class="welcome-text">
              <h1 class="welcome-title">欢迎回来，管理员</h1>
              <p class="welcome-date">今天是{{ new Date().toLocaleDateString('zh-CN', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) }}</p>
            </div>
            <div class="welcome-decoration">
              <div class="decoration-shape"></div>
            </div>
          </div>
        </div>
      </t-col>

      <!-- 数据概览 -->
      <t-col :span="6">
        <t-card title="用户总数" class="stat-card">
          <div class="stat-value">{{ statistics.userCount }}</div>
          <div class="stat-icon" style="background-color: rgba(24, 144, 255, 0.1)">
            <t-icon name="user" style="color: #1890ff" />
          </div>
        </t-card>
      </t-col>
      
      <t-col :span="6">
        <t-card title="订单总数" class="stat-card">
          <div class="stat-value">{{ statistics.orderCount }}</div>
          <div class="stat-icon" style="background-color: rgba(82, 196, 26, 0.1)">
            <t-icon name="shop" style="color: #52c41a" />
          </div>
        </t-card>
      </t-col>
      
      <t-col :span="6">
        <t-card title="景点数量" class="stat-card">
          <div class="stat-value">{{ statistics.attractionCount }}</div>
          <div class="stat-icon" style="background-color: rgba(114, 46, 209, 0.1)">
            <t-icon name="location" style="color: #722ed1" />
          </div>
        </t-card>
      </t-col>
      
      <t-col :span="6">
        <t-card title="活动数量" class="stat-card">
          <div class="stat-value">{{ statistics.activityCount }}</div>
          <div class="stat-icon" style="background-color: rgba(250, 173, 20, 0.1)">
            <t-icon name="calendar" style="color: #faad14" />
          </div>
        </t-card>
      </t-col>

      <!-- 收入统计 -->
      <t-col :span="12">
        <t-card title="总收入" class="stat-card">
          <div class="stat-value">{{ formatCurrency(statistics.totalRevenue) }}</div>
          <div class="stat-trend">
            <t-icon name="arrow-up" style="color: #52c41a" />
            <span style="color: #52c41a">8.5%</span>
            <span class="trend-text">较上月</span>
          </div>
        </t-card>
      </t-col>
      
      <t-col :span="12">
        <t-card title="今日收入" class="stat-card">
          <div class="stat-value">{{ formatCurrency(statistics.todayRevenue) }}</div>
          <div class="stat-trend">
            <t-icon name="arrow-up" style="color: #52c41a" />
            <span style="color: #52c41a">12.3%</span>
            <span class="trend-text">较昨日</span>
          </div>
        </t-card>
      </t-col>

      <!-- 快速入口 -->
      <t-col :span="24">
        <t-card title="快速入口">
          <t-row :gutter="[16, 16]">
            <t-col :span="4" v-for="(entry, index) in quickEntries" :key="index">
              <router-link :to="entry.path" class="quick-entry-link">
                <div class="quick-entry" :style="{ borderColor: entry.color }">
                  <t-icon :name="entry.icon" :style="{ color: entry.color }" />
                  <span>{{ entry.title }}</span>
                </div>
              </router-link>
            </t-col>
          </t-row>
        </t-card>
      </t-col>

      <!-- 待办事项 -->
      <t-col :span="12">
        <t-card title="待办事项">
          <t-list>
            <t-list-item v-for="(item, index) in todoList" :key="index">
              <div class="todo-item">
                <t-tag
                  :theme="item.status === 'urgent' ? 'danger' : item.status === 'pending' ? 'warning' : 'primary'"
                  :variant="item.status === 'normal' ? 'light' : 'dark'"
                  size="small"
                >
                  {{ item.status === 'urgent' ? '紧急' : item.status === 'pending' ? '待处理' : '普通' }}
                </t-tag>
                <span class="todo-title">{{ item.title }}</span>
                <span class="todo-time">{{ item.time }}</span>
              </div>
            </t-list-item>
          </t-list>
        </t-card>
      </t-col>

      <!-- 系统公告 -->
      <t-col :span="12">
        <t-card title="系统公告">
          <t-list>
            <t-list-item v-for="(notice, index) in notices" :key="index">
              <div class="notice-item">
                <div class="notice-header">
                  <span class="notice-title">{{ notice.title }}</span>
                  <span class="notice-date">{{ notice.date }}</span>
                </div>
                <div class="notice-content">{{ notice.content }}</div>
              </div>
            </t-list-item>
          </t-list>
        </t-card>
      </t-col>
    </t-row>
  </div>
</template>

<style scoped>
.home-container {
  padding: 0;
  background-color: transparent;
}

.welcome-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 32px;
  color: white;
  position: relative;
  overflow: hidden;
  margin-bottom: 8px;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
}

.welcome-title {
  margin: 0 0 12px 0;
  font-size: 28px;
  font-weight: 600;
  color: white;
}

.welcome-date {
  margin: 0;
  font-size: 16px;
  opacity: 0.9;
  color: rgba(255, 255, 255, 0.9);
}

.welcome-decoration {
  position: relative;
  width: 120px;
  height: 80px;
}

.decoration-shape {
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  transform: translate(20px, -20px);
}

.decoration-shape::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 20px;
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.decoration-shape::after {
  content: '';
  position: absolute;
  top: 10px;
  left: -10px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.stat-card {
  position: relative;
  height: 100%;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  margin-top: 8px;
}

.stat-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stat-icon :deep(svg) {
  font-size: 24px;
}

.stat-trend {
  display: flex;
  align-items: center;
  margin-top: 8px;
  font-size: 14px;
}

.trend-text {
  margin-left: 8px;
  color: #999;
}

.quick-entry-link {
  text-decoration: none;
  color: inherit;
}

.quick-entry {
  height: 80px;
  border-radius: 4px;
  border: 1px solid #e8e8e8;
  border-left-width: 4px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: all 0.3s;
}

.quick-entry:hover {
  transform: translateY(-4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
}

.quick-entry :deep(svg) {
  font-size: 24px;
  margin-bottom: 8px;
}

.todo-item {
  display: flex;
  align-items: center;
}

.todo-title {
  margin-left: 12px;
  flex: 1;
}

.todo-time {
  color: #999;
  font-size: 14px;
}

.notice-item {
  display: flex;
  flex-direction: column;
}

.notice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.notice-title {
  font-weight: bold;
}

.notice-date {
  color: #999;
  font-size: 14px;
}

.notice-content {
  color: #666;
  font-size: 14px;
}
</style>
